﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleData.ObjectModel.Design;
using SimpleData.ObjectModel;

namespace SimpleData
{
	public static class FieldDataGenExtensions
	{

		public static DataGenEntityBuilder<FieldDescriptor> Field( this DGen dgen )
		{
			return dgen.Field( null, null );
		}

		public static DataGenEntityBuilder<FieldDescriptor> Field( this DGen dgen, string name )
		{
			return dgen.Field( name, null );
		}

		public static DataGenEntityBuilder<FieldDescriptor> Field( this DGen dgen, FieldTypeDescriptor fieldType )
		{
			return dgen.Field( null, fieldType );
		}

		public static DataGenEntityBuilder<FieldDescriptor> Field( this DGen dgen, string name, FieldTypeDescriptor fieldType )
		{
			FieldName fieldName = new FieldName( dgen.GetRandomName( name ) );

			if(fieldType == null )
				fieldType = dgen.FieldType().Get();

			FieldDescriptor field = new FieldDescriptor( fieldName, fieldType );

			field.DisplayName = dgen.GetRandomName( "displayName " );

			return new DataGenEntityBuilder<FieldDescriptor>( dgen, field );
		}

		public static DataGenEntityBuilder<FieldDescriptor> Rule( this DataGenEntityBuilder<FieldDescriptor> builder, IRuleBuilder ruleBuilder )
		{
			var rule = new FieldRule( new RuleName( builder.Entity.Name.Name ), builder.Entity );

			//rule.Factory = Runtime.Current.Mocks().RuleBuilderFactory().Create( () => ruleBuilder ).Get();
			builder.Entity.Rules.Add( rule );

			return builder;
		}


	}
}
